package com.graphics;
/**
* @author Dror
*
* email: gumjum.o.o@gmail.com
*
*/
import java.awt.Color;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.math.Quat;
import com.math.Vector;
public class ConnectingOval extends Oval {
boolean []isBridged;
public ConnectingOval(Camera cam,Vector dim,Vector pos,Quat rot,Color color) {//Vector rot
super(cam, dim, pos, rot,color);
}
public ConnectingOval(Camera cam, Vector dim, Color color) {
super(cam, dim,color);
}
public void build(){
for(int i = 0;i<points_num;i++)
points[i] = new Vector();
isBridged = new boolean[points_num];
for(int i = 0;i<points_num;i++){
isBridged[i] = false;
}
bridg();
}
public void bridgPoint(int i,Vector p){
this.points[i] = p;
this.isBridged[i] = true;
this.bridg();
}
public void rebuild() {
float sx = -d.x,sy;
float step = 2*d.x / (half/2 - 1);
float asq = d.x*d.x,b = d.y;
for(int i = 0;i<half/2;i++){
sy =(float)(b*Math.sqrt(1-(sx*sx-0.001)/(asq)));
if(i==0 || i == half/2){
if(!isBridged[i])
points[i] .set(sx, sy,+d.z);
if(!isBridged[half-i-1])
points[half-i-1] .set(sx, sy,+d.z);
if(!isBridged[i+half])
points[i+half] .set(sx, sy,-d.z);
if(!isBridged[half-i-1+ half])
points[half-i-1+ half].set(sx, sy,-d.z);
}else{
if(!isBridged[i])
points[i] .set(sx, sy,+d.z);
if(!isBridged[half-i-1])
points[half-i-1] .set(sx,-sy,+d.z);
if(!isBridged[i+half])
points[i+half] .set(sx, sy,-d.z);
if(!isBridged[half-i-1+ half])
points[half-i-1+ half].set(sx,-sy,-d.z);
}
sx += step;
}
for(int i=0;i<points_num;i++){
if(!isBridged[i]){
points[i].transformation(r,p);
points[i].reverseTransformation(cam.r, cam.p);
}
}
tmp.reverseTransformation(cam.r, cam.p,p);
compare_z = (int)(tmp.z);
}
public Element toXML(Document doc){
Element oval = doc.createElement("ConnectingOval");
oval.setAttribute("position", p+"");
oval.setAttribute("rotation", r+"");
oval.setAttribute("dimmention", d+"");
oval.setAttribute("color", def_color.getRGB()+"");
return oval;
}
public static ConnectingOval fromXML(Element e, Camera cam){
Color color = new Color(Integer.parseInt(e.getAttribute("color")));
Vector d = Vector.parseVector(e.getAttribute("dimmention"));
Vector p = Vector.parseVector(e.getAttribute("position"));
Quat r = Quat.parseQuat(e.getAttribute("rotation"));
return new ConnectingOval(cam,d,p,r,color);
}
}